package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.OrderDao;
import ysq.xyg.model.Order;
import ysq.xyg.service.OrderService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:37
 **/
@Service("orderService")
public class OrderServiceImpl extends BaseServiceImpl<Order> implements OrderService {
    @Resource
    private OrderDao orderDao;

    @Autowired
    public void setBaseDao(OrderDao orderDao) {
        this.baseDao = orderDao;
    }
    @Override
    public int selectMaxId(Order order) {
        return orderDao.selectMaxId(order);
    }
    @Override
    public PageInfo<Order> pageInfoLeft(Order order, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        List<Order> list=orderDao.listLeft(order);
        return new PageInfo<Order>(list);
    }
    @Override
    public List<Order> listLeft(Order order) {
        //通用Example查询
        List<Order> list=orderDao.listLeft(order);
        return list;
    }
    @Override
    public PageInfo<Order> pageInfo(Order order, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        PageHelper.orderBy(" create_time desc ");
        Example example = new Example(Order.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(order.getMemberId())){
            criteria.andEqualTo("memberId",order.getMemberId());
        }
        if(StringUtil.isNotEmpty(order.getName())){
            criteria.andLike("name","%"+order.getName()+"%");
        }
        List<Order> list=orderDao.selectByExample(example);
        return new PageInfo<Order>(list);
    }
    @Override
    public List<Order> list(Order order) {
        //通用Example查询
        Example example = new Example(Order.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(order.getMemberId())){
            criteria.andEqualTo("memberId",order.getMemberId());
        }
        if(StringUtil.isNotEmpty(order.getName())){
            criteria.andLike("name","%"+order.getName()+"%");
        }
        example.setOrderByClause(" create_time desc ");
        List<Order> list=orderDao.selectByExample(example);
        return list;
    }
}
